# coding=utf-8


# list列表

list_test = [1, 34, 45, 21, 21, 1, 51]

# C(create) | U(update)
list_test.insert(5, 'a')  # 索引增值，可随意按照范围内索引进行添加value
print(list_test)  # [1, 34, 45, 21, 21, 'a', 1, 51]

list_test.append('chen')  # 只在列表末尾追加
print(list_test)  # [1, 34, 45, 21, 21, 'a', 1, 51, 'chen']

# D(delete)
list_test.pop()  # 默认删除列表末尾元素
print(list_test)  # [1, 34, 45, 21, 21, 'a', 1, 51]

# list_test.remove('link')
# print(list_test) # ValueError: list.remove(x): x not in list
list_test.remove('a')  # 移除列表元素， 有则移除，无则报错
print(list_test)  # [1, 34, 45, 21, 21, 1, 51]

del list_test[1]  # 删除指定索引下的元素
print(list_test)  # [1, 45, 21, 21, 1, 51]

# r(retrieve)
print([test for test in enumerate(list_test)])  # [(index, value)]

# tuple (元组不可变只有查，没有增删改)

tuple_test = ('a', 'g', 'r', 'a', 'h')
print(tuple(enumerate(tuple_test)))  # ((0, 'a'), (1, 'g'), (2, 'r'), (3, 'a'), (4, 'h'))枚举方法.....

# dict 字典

dict_test = {
    'Sec-Fetch-Dest': 'document',
    'Sec-Fetch-Mode': 'navigate',
    'Sec-Fetch-Site': 'none',
}

# C(create)
dict_test[
    'User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36'
print(
    dict_test)  # {'Sec-Fetch-Dest': 'document', 'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-Site': 'none', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36'}

# r (retrieve)
for key, value in dict_test.items():
    print(key, '|', value)
    """
    Sec-Fetch-Dest | document
    Sec-Fetch-Mode | navigate
    Sec-Fetch-Site | none
    User-Agent | Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36
"""

print(dict_test.keys())  # dict_keys(['Sec-Fetch-Dest', 'Sec-Fetch-Mode', 'Sec-Fetch-Site', 'User-Agent'])
print(
    dict_test.values())  # dict_values(['document', 'navigate', 'none', 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36'])

# U(update)
dict_test['User-Agent'] = 'user-agent'
print(
    dict_test)  # {'Sec-Fetch-Dest': 'document', 'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-Site': 'none', 'User-Agent': 'user-agent'}
dict_test.setdefault('name', 'python')
print(
    dict_test)  # {'Sec-Fetch-Dest': 'document', 'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-Site': 'none', 'User-Agent': 'user-agent', 'name': 'python'}

# D(delete)
del dict_test['User-Agent']
print(
    dict_test)  # {'Sec-Fetch-Dest': 'document', 'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-Site': 'none', 'name': 'python'}

# set集合

# 增加
set_test = {'g', 1, 'gg', 'w', 25}
set_test.add('python')
print(set_test)  # {1, 'python', 'w', 'g', 25, 'gg'}

# 删除
set_test.discard('gg')
print(set_test)  # {1, 'w', 'g', 'python', 25}
